﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ETA.IRepository;
using ETA.IService;

namespace ETA.Service
{
    public class BannerService : IBannerService
    {
        #region 属性

        private IFeatureBannerRepository _IFeatureBannerRepository { set; get; }


        #endregion

        #region 构造函数

        public BannerService(IFeatureBannerRepository IFeatureBannerRepository)
        {
            _IFeatureBannerRepository = IFeatureBannerRepository;
        }

        #endregion

        #region IBannerService 成员

        public QueryBannerResponse QueryFeatureBannerList(QueryBannerRequest req)
        {
            var response = new QueryBannerResponse();
            try
            {
                if (!string.IsNullOrEmpty(req.FeatureBannerId))
                {
                    response.BannerList = _IFeatureBannerRepository.GetAllList(b => b.FeatureBannerId == req.FeatureBannerId);
                }
                else if (!string.IsNullOrEmpty(req.BannerKind))
                {
                    response.BannerList = _IFeatureBannerRepository.GetAllList(b => b.UploadFile.FileType.FileTypeName == req.BannerKind);
                }
                else
                {
                    response.BannerList = _IFeatureBannerRepository.GetAllList();
                }
                response.Result.IsSuccess = true;
            }
            catch (Exception e)
            {
                response.Result.Message = e.Message;
            }
            return response;
        }

        #endregion


        public CreateBannerResponse CreateFeatureBanner(CreateBannerRequest req)
        {
            var res = new CreateBannerResponse();
            try
            {
                if (req != null)
                {
                    res.Banner = _IFeatureBannerRepository.Insert(req.Banner);
                    res.Result.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                res.Result.IsSuccess = false;
                res.Result.ErrMessage = e.Message;
            }
            return res;
        }

        public ModifyBannerResponse ModifyFeatureBanner(ModifyBannerRequest req)
        {
            var res = new ModifyBannerResponse();
            try
            {
                if (req != null)
                {
                    res.Banner = _IFeatureBannerRepository.Update(req.Banner);
                    res.Result.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                res.Result.IsSuccess = false;
                res.Result.ErrMessage = e.Message;
            }
            return res;
        }

    }
}
